#!/bin/bash
#

cpu=`top -n 1  | grep  %Cpu |  awk '{print $2}'`
if [[ $cpu > "80" ]];then
   echo "cpu当前剩余 $cpu% 已经不够用啦" | mail -s "cpu当前剩余 $cpu% 已经不够用啦! 请及时处理" 25062652222@qq.com
else
   echo $cpu
fi

available=`free -h  | awk 'NR==2{print $7}'`
total=`free -h  | awk 'NR==2{print $2}'`
if [ $available == $total ];then
   echo "内存当前剩余 $available 已经不够用啦" | mail -s "内存当前剩余 $available 已经不够用啦! 请及时处理" 25062652222@qq.com
else
   echo $available
fi

free=`free  -m  | grep  Mem  |tr -s " "|cut -d " " -f 7`
avg=`awk 'BEGIN{printf "%.2f%%\n",(100/'$free')*100}'`
if [[ $avg > "80%" ]];then
   echo "内存当前剩余 $avg 已经不够用啦" | mail -s "内存当前剩余 $avg 已经不够用啦! 请及时处理" 25062652222@qq.com
else
   echo $avg
fi

DF=`df -hT  | grep "/$" | awk '{print $(NF-1)}'`
if [ "$DF" == "90%" ];then
   echo "磁盘当前剩余 $DF 已经不够用啦！" | mail -s "磁盘当前剩余 $DF 已经不够用啦！ 请及时处理" 25062652222@qq.com
else
   echo $DF
fi